from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-19 14:02:41.262659
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 19, Jun, 2022
Time: 14:02:46
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5450
Nobs: 692.000 HQIC: -49.9071
Log likelihood: 8599.71 FPE: 1.68449e-22
AIC: -50.1354 Det(Omega_mle): 1.48043e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300297 0.058426 5.140 0.000
L1.Burgenland 0.107689 0.038134 2.824 0.005
L1.Kärnten -0.109610 0.020180 -5.432 0.000
L1.Niederösterreich 0.212634 0.079726 2.667 0.008
L1.Oberösterreich 0.104628 0.078245 1.337 0.181
L1.Salzburg 0.257012 0.040797 6.300 0.000
L1.Steiermark 0.044939 0.053426 0.841 0.400
L1.Tirol 0.109773 0.043144 2.544 0.011
L1.Vorarlberg -0.057648 0.037398 -1.541 0.123
L1.Wien 0.035467 0.069211 0.512 0.608
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055038 0.122761 0.448 0.654
L1.Burgenland -0.035817 0.080125 -0.447 0.655
L1.Kärnten 0.041288 0.042400 0.974 0.330
L1.Niederösterreich -0.179798 0.167514 -1.073 0.283
L1.Oberösterreich 0.431700 0.164401 2.626 0.009
L1.Salzburg 0.288085 0.085720 3.361 0.001
L1.Steiermark 0.104913 0.112254 0.935 0.350
L1.Tirol 0.316423 0.090651 3.491 0.000
L1.Vorarlberg 0.028497 0.078578 0.363 0.717
L1.Wien -0.043087 0.145421 -0.296 0.767
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186773 0.029899 6.247 0.000
L1.Burgenland 0.090121 0.019515 4.618 0.000
L1.Kärnten -0.007770 0.010327 -0.752 0.452
L1.Niederösterreich 0.263502 0.040799 6.459 0.000
L1.Oberösterreich 0.137908 0.040041 3.444 0.001
L1.Salzburg 0.045470 0.020877 2.178 0.029
L1.Steiermark 0.023095 0.027340 0.845 0.398
L1.Tirol 0.090517 0.022078 4.100 0.000
L1.Vorarlberg 0.057131 0.019138 2.985 0.003
L1.Wien 0.114510 0.035418 3.233 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110826 0.030315 3.656 0.000
L1.Burgenland 0.044903 0.019786 2.269 0.023
L1.Kärnten -0.013540 0.010470 -1.293 0.196
L1.Niederösterreich 0.188975 0.041367 4.568 0.000
L1.Oberösterreich 0.304431 0.040598 7.499 0.000
L1.Salzburg 0.106274 0.021168 5.021 0.000
L1.Steiermark 0.107833 0.027721 3.890 0.000
L1.Tirol 0.102215 0.022386 4.566 0.000
L1.Vorarlberg 0.068950 0.019404 3.553 0.000
L1.Wien -0.021719 0.035911 -0.605 0.545
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132611 0.055581 2.386 0.017
L1.Burgenland -0.050582 0.036277 -1.394 0.163
L1.Kärnten -0.044477 0.019197 -2.317 0.021
L1.Niederösterreich 0.151170 0.075844 1.993 0.046
L1.Oberösterreich 0.143072 0.074434 1.922 0.055
L1.Salzburg 0.284907 0.038810 7.341 0.000
L1.Steiermark 0.051904 0.050824 1.021 0.307
L1.Tirol 0.166592 0.041043 4.059 0.000
L1.Vorarlberg 0.094680 0.035577 2.661 0.008
L1.Wien 0.072553 0.065841 1.102 0.270
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059289 0.043973 1.348 0.178
L1.Burgenland 0.035182 0.028701 1.226 0.220
L1.Kärnten 0.051289 0.015188 3.377 0.001
L1.Niederösterreich 0.212026 0.060004 3.534 0.000
L1.Oberösterreich 0.294562 0.058889 5.002 0.000
L1.Salzburg 0.045798 0.030705 1.492 0.136
L1.Steiermark 0.006924 0.040210 0.172 0.863
L1.Tirol 0.138700 0.032471 4.271 0.000
L1.Vorarlberg 0.074769 0.028147 2.656 0.008
L1.Wien 0.082165 0.052090 1.577 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172420 0.052818 3.264 0.001
L1.Burgenland -0.002008 0.034474 -0.058 0.954
L1.Kärnten -0.062922 0.018243 -3.449 0.001
L1.Niederösterreich -0.082389 0.072074 -1.143 0.253
L1.Oberösterreich 0.195351 0.070734 2.762 0.006
L1.Salzburg 0.056212 0.036881 1.524 0.127
L1.Steiermark 0.241255 0.048298 4.995 0.000
L1.Tirol 0.496582 0.039003 12.732 0.000
L1.Vorarlberg 0.045303 0.033809 1.340 0.180
L1.Wien -0.057238 0.062568 -0.915 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162718 0.059998 2.712 0.007
L1.Burgenland -0.013135 0.039160 -0.335 0.737
L1.Kärnten 0.064531 0.020723 3.114 0.002
L1.Niederösterreich 0.201786 0.081871 2.465 0.014
L1.Oberösterreich -0.074981 0.080350 -0.933 0.351
L1.Salzburg 0.210146 0.041895 5.016 0.000
L1.Steiermark 0.136043 0.054864 2.480 0.013
L1.Tirol 0.063363 0.044305 1.430 0.153
L1.Vorarlberg 0.119760 0.038405 3.118 0.002
L1.Wien 0.132327 0.071074 1.862 0.063
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.368487 0.034768 10.599 0.000
L1.Burgenland 0.006220 0.022693 0.274 0.784
L1.Kärnten -0.023501 0.012008 -1.957 0.050
L1.Niederösterreich 0.217649 0.047443 4.588 0.000
L1.Oberösterreich 0.203105 0.046561 4.362 0.000
L1.Salzburg 0.044065 0.024277 1.815 0.070
L1.Steiermark -0.017559 0.031792 -0.552 0.581
L1.Tirol 0.106104 0.025674 4.133 0.000
L1.Vorarlberg 0.069557 0.022255 3.125 0.002
L1.Wien 0.027965 0.041186 0.679 0.497
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037163 0.134464 0.191390 0.152835 0.114127 0.098564 0.055815 0.216612
Kärnten 0.037163 1.000000 -0.017294 0.133417 0.055121 0.092812 0.436518 -0.054558 0.093199
Niederösterreich 0.134464 -0.017294 1.000000 0.335046 0.140564 0.292974 0.087672 0.173047 0.311328
Oberösterreich 0.191390 0.133417 0.335046 1.000000 0.226475 0.322612 0.173425 0.158898 0.264980
Salzburg 0.152835 0.055121 0.140564 0.226475 1.000000 0.138017 0.113604 0.137715 0.132426
Steiermark 0.114127 0.092812 0.292974 0.322612 0.138017 1.000000 0.145053 0.125781 0.072190
Tirol 0.098564 0.436518 0.087672 0.173425 0.113604 0.145053 1.000000 0.109072 0.142414
Vorarlberg 0.055815 -0.054558 0.173047 0.158898 0.137715 0.125781 0.109072 1.000000 0.005196
Wien 0.216612 0.093199 0.311328 0.264980 0.132426 0.072190 0.142414 0.005196 1.000000